home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 3
/
L'Effet Pommier - Volume 03.iso
/
Programmation
/
Alpha ƒ
/
Tcl
/
SystemCode
/
c.tcl
< prev
next >
Wrap
Text File
|
1996-01-22
|
12KB
|
405 lines
newModeVar C elecColon {1} 1
newModeVar C elecRBrace {1} 1
newModeVar C leftFillColumn {3} 0
newModeVar C prefixString {//} 0
newModeVar C electricSemi {1} 1
newModeVar C wordBreak {[a-zA-Z0-9_]+} 0
newModeVar C elecLBrace {1} 1
newModeVar C elecElse {1} 1
newModeVar C wordWrap {0} 1
newModeVar C funcExpr {^[^ \t\(#\r/@].*\(.*\)$} 0
newModeVar C wordBreakPreface {[^a-zA-Z0-9_]} 0
newModeVar C electricTab {0} 1
newModeVar C autoMark 0 1
newModeVar C stringColor green 0
newModeVar C commentColor red 0
newModeVar C keywordColor blue 0
set cCommentRegexp {/\*(([^*]/)|[^*]|\r)*\*/}
set cPreRegexp {^\#[\t ]*[a-z]*}
set cKeyWords {
void break register short enum extern int for if while struct static long continue
switch case char unsigned double float return else default goto do pascal Boolean
typedef volatile union auto sizeof size_t
}
if {[info exists Cwords]} {set cKeyWords [concat $cKeyWords $Cwords]}
regModeKeywords -e {//} -b {/*} {*/} -c $CmodeVars(commentColor) -k $CmodeVars(keywordColor) -s $CmodeVars(stringColor) -m {#} C $cKeyWords
#================================================================================
newModeVar C++ elecColon {1} 1
newModeVar C++ elecRBrace {1} 1
newModeVar C++ leftFillColumn {3} 0
newModeVar C++ prefixString {//} 0
newModeVar C++ electricSemi {1} 1
newModeVar C++ wordBreak {[a-zA-Z0-9_]+} 0
newModeVar C++ elecLBrace {1} 1
newModeVar C++ elecElse {1} 1
newModeVar C++ wordWrap {0} 1
newModeVar C++ funcExpr {^[^ \t\(#\r/@].*\(.*\)$} 0
newModeVar C++ wordBreakPreface {[^a-zA-Z0-9_]} 0
newModeVar C++ electricTab {1} 1
newModeVar C++ autoMark 0 1
newModeVar C++ stringColor green 0
newModeVar C++ commentColor green 0
newModeVar C++ keywordColor blue 0
set {c++KeyWords} {
new delete class friend protected private public template
try catch throw operator const mutable virtual asm inline this
and and_eq bitand bitor compl not or or_eq xor xor_eq not_eq
wchar_t bool true false
static_cast dynamic_cast reinterpret_cast typeid
using namespace inherited
}
if {[info exists {C++words}]} {
set {c++KeyWords} [concat ${c++KeyWords} ${C++words} $cKeyWords]
} else {
set {c++KeyWords} [concat ${c++KeyWords} $cKeyWords]
}
regModeKeywords -e {//} -b {/*} {*/} -c [set C++modeVars(commentColor)] -k [set C++modeVars(keywordColor)] -s [set C++modeVars(stringColor)] -m {#} {C++} ${c++KeyWords}
unset cKeyWords
unset {c++KeyWords}
#=============================================================================
# "Electric" C functions.
#=============================================================================
# returns the indent string of the line named by 'pos'
proc indentString pos {
set start [lineStart $pos]
set end [nextLineStart $pos]
set text [getText $start $end]
for {set i 0} {1} {incr i} {
set c [string index $text $i]
if {($c != "\ ") && ($c != "\t")} then {
return [string range $text 0 [expr $i-1]]
}
}
return
}
# Brace on new line, same indentation. Insert on another new line, indented in.
# First, see if we are on new line.
proc electricCLeft {} {
global mode
global ${mode}modeVars
deleteText [getPos] [selEnd]
if {![set ${mode}modeVars(elecLBrace)]} then {
insertText "\{"
return
}
if {[set ${mode}modeVars(elecLBrace)] && ![catch {search -l [lineStart [expr [lineStart [getPos]] - 1]] -s -f 0 -r 0 "\}" [getPos]} res]} {
if {[regexp {\}[ \t\r]*else} [getText [lindex $res 0] [expr [getPos] + 1]]]} {
set res2 [search -f 0 -r 0 {else} [getPos]]
oneSpace
set text [getText [lindex $res2 0] [getPos]]
if {[lookAt [expr [getPos] - 1]] != " "} {
append text " "
}
replaceText [expr [lindex $res 0] + 1] [getPos] " $text\{\r"
indentLine
return
}
}
set pos [getPos]
set start [lineStart $pos]
set text [getText $start $pos]
for {set i $start} {$i < $pos} {incr i} {
set c [lookAt $i]
if {($c != "\ ") && ($c != "\t")} then {
break;
}
}
set indentation [getText $start $i]
if {($i == $pos) || ([lookAt $pos] == " ")} {
insertText "\{\r" $indentation "\t"
} else {
insertText " \{\r" $indentation "\t"
}
}
bind '\{' <s> electricCLeft C
bind '\{' <s> electricCLeft C++
# Brace on new line, immediate carriage return
proc electricCRight {} {
global mode
global ${mode}modeVars
deleteText [getPos] [selEnd]
if {[set ${mode}modeVars(elecRBrace)] == "0"} then {
insertText "\}"
catch {blink [matchIt "\}" [expr [getPos]-2]]}
return
}
set pos [getPos]
set start [lineStart $pos]
if {[catch {matchIt "\}" [expr $pos-1]} matched]} {
beep
return
}
set text [getText [lineStart $matched] $matched]
regexp {^[ ]*} $text indentation
for {set i $start} {$i < $pos} {incr i} {
set c [lookAt $i]
if {($c != "\ ") && ($c != "\t")} then {
insertText "\r" $indentation "\}\r" $indentation
blink $matched
return
}
}
set text [set indentation]\}\r$indentation
replaceText $start $pos $text
goto [expr {$start + [string length $text]}]
blink [matchIt "\}" [expr $start-2]]
}
bind '\}' <s> electricCRight C
bind '\}' <s> electricCRight C++
# Brace on new line, immediate carriage return. We don't do our electric stuff
# if we are in the middle of a for statement.
proc electricCSemi {} {
global mode
global ${mode}modeVars
deleteText [getPos] [selEnd]
if {[set ${mode}modeVars(electricSemi)] == "0"} then {
insertText ";"
return
}
set pos [getPos]
set start [lineStart $pos]
set text [getText $start $pos]
if {[string first "for" $text] != "-1"} {
set lefts 0
set rights 0
set len [string length $text]
for {set i 0} {$i < $len} {incr i} {
case [string index $text $i] in {
"(" { incr lefts }
")" { incr rights }
}
}
global globs
set globs [list $lefts $rights $len]
if {$lefts != $rights} {
insertText ";"
return
}
}
insertText ";\r" [indentString $pos]
}
bind '\;' electricCSemi C
bind '\;' electricCSemi C++
proc ordSemi {} {
insertText {;}
}
bind '\;' <z> ordSemi
proc cppCR {} {
if {[lookAt [expr [getPos] - 1]] == ":"} {
if { [lookAt [getPos]] == "\r" } {
indentLine
endOfLine
carriageReturn
} else {
set pos [getPos]
endOfLine
set t [getText $pos [getPos]]
replaceText $pos [getPos] ""
indentLine
endOfLine
carriageReturn
insertText $t
}
indentLine
} else {
carriageReturn
indentLine
}
}
bind '\r' cppCR C
bind '\r' cppCR C++
#================================================================================
# proc CMarkFile {} {
# global CmodeVars
# set pos 0
# while {![catch {search -s -f 1 -r 1 -m 0 -i 0 $CmodeVars(funcExpr) $pos} res]} {
# set start [lindex $res 0]
# set end [expr [lindex $res 1] + 1]
# set text [getText $start $end]
# if {[regexp {([a-zA-Z0-9:_]+)[ \t]*\(} $text dummy word]} {
# set tmp [expr $start + [string first $word $text]]
# set inds($word) "$tmp [expr $tmp + [string length $word]]"
# }
# set pos $end
# }
# if {[info exists inds]} {
# foreach f [lsort -ignore [array names inds]] {
# set res $inds($f)
# setNamedMark $f [lineStart [lindex $res 0]] [lindex $res 0] [lindex $res 1]
# }
# }
# }
#
#
# #The previous version would not find things like void *ThisFunc( xxx ) due to the asterisk
# #I also truncated the pattern. The rest is not necessary and intrusive as far as I can tell
# proc C++MarkFile {} {
# set pos 0
# while {![catch {search -s -f 1 -r 1 -m 0 -i 0 {^([^ \t\(#\r/@].*[ \t]+)?\*?([A-Za-z0-9:~_]+)[ \t\r]*\(} $pos} res]} {
# set start [lindex $res 0]
# set end [expr [lindex $res 1] + 1]
# set thistext [getText $start $end]
# #regexp doesn't like carriage returns
# regsub -all "\r" $thistext " " thistext
# #regexp doesn't like tabs either
# regsub -all "\t" $thistext " " thistext
# #if the open paren was the last character on the line the selected text included the last carriage return as well
# #trim this off now that it is changed into a space
# set thistext [string trimright $thistext]
# if {[regexp {([a-zA-Z0-9:~_]+)[ \t]*\(} $thistext dummy word]} {
# set inds($word) [lineStart [expr $start - 1]]
# }
# set pos $end
# }
# if {[info exists inds]} {
# foreach f [lsort -ignore [array names inds]] {
# set next [nextLineStart $inds($f)]
# setNamedMark $f $inds($f) $next $next
# }
# }
# }
proc CMarkFile {} {
global CmodeVars
set pos 0
while {![catch {search -s -f 1 -r 1 -m 0 -i 0 $CmodeVars(funcExpr) $pos} res]} {
set start [lindex $res 0]
set end [expr [lindex $res 1] + 1]
set text [getText $start $end]
if {[regexp {([a-zA-Z0-9:_]+)[ \t]*\(} $text dummy word]} {
set tmp [expr $start + [string first $word $text]]
set inds($word) "$tmp [expr $tmp + [string length $word]]"
}
set pos $end
}
##
# Also mark any class or struct definitions
##
set markExpr {^(class|struct) [A-Za-z0-9_]+[ \t]*(:|\{)}
while {![catch {search -s -f 1 -r 1 -m 0 -i 0 "$markExpr" $pos} res]} {
set start [lindex $res 0]
set end [expr [lindex $res 1] -1]
set text [string trimright [getText $start $end] ]
set inds($text) "$start [expr $start + [string length $text]]"
set pos $end
}
if {[info exists inds]} {
foreach f [lsort -ignore [array names inds]] {
set res $inds($f)
setNamedMark $f [lineStart [lindex $res 0]] [lindex $res 0] [lindex $res 1]
}
}
}
proc C++MarkFile {} {
set pos 0
set markExpr {^([^ \t\(#\r/@].*[ \t]+)?\*?([A-Za-z0-9<>~_]+::[-A-Za-z0-9~_+=\*/]+|[A-Za-z0-9~_]+)[ \t\r]*\(}
while {![catch {search -s -f 1 -r 1 -m 0 -i 0 "$markExpr" $pos} res]} {
set start [lindex $res 0]
set end [expr [lindex $res 1] + 1]
set thistext [getText $start $end]
#regexp doesn't like carriage returns
regsub -all "\r" $thistext " " thistext
#regexp doesn't like tabs either
regsub -all "\t" $thistext " " thistext
#if the open paren was the last character on the line the selected text
#included the last carriage return as well
#trim this off now that it is changed into a space
set thistext [string trimright $thistext]
if {[regexp {([A-Za-z0-9<>~_]+::[-A-Za-z0-9~_+=\*/]+|[A-Za-z0-9~_]+)[ \t]*\(} $thistext dummy word]} {
if { [string first "::" $word] != -1 } {
regsub {(<[A-Za-z0-9_]+>)?::} $word " " it
set l [lindex $it 0]
if { $l == [lindex $it 1] } {
set word "Construct '$l'"
} elseif { "~$l" == [lindex $it 1] } {
set word "Destruct '$l'"
}
}
set inds($word) [lineStart [expr $start - 1]]
}
set pos $end
}
if {[info exists inds]} {
foreach f [lsort -ignore [array names inds]] {
set next [nextLineStart $inds($f)]
# Alpha doesn't like '<' or '>' in the mark menu
regsub -all {[<>]+} $f "|" it
if {[string length $it] > 35} { set it "[string range $it 0 31]..." }
setNamedMark "${it}" "$inds($f)" $next $next
}
}
}
proc setC++Mode {} {
changeMode "C++"
}
source "$HOME:Tcl:SystemCode:think.tcl"
proc dummyC {} {}
proc dummyC++ {} {}
#===============================================================================
proc CDblClick {from to} {
global tagFile
select $from $to
set text [getSelect]
set lines [grep "^$text'" $tagFile]
if {[regexp {'(.*)'(.*[^\t])(\t)+░} $lines dummy one two]} {
if {[string match "*$one*" [winNames -f]]} {
bringToFront $one
} else {
edit $one
}
set inds [search -f 1 -r 0 "$two" 0]
display [lindex $inds 0]
eval select $inds
} else {
checkRunning ThinkReference DanR referencePath
AEBuild {'DanR'} DanR {REF } "----" "╥$text╙"
}
}
proc C++DblClick {from to shift option control} {
CDblClick $from $to
}